import { BULLET_SPEED } from '../../../config/play_def';
import tower from '../../base/tower'
cc.Class({
    extends: tower,

    properties: {},
    initInfo(param,role_info){
        this._super(param,role_info)
        this.attack_status = true
        this.bone = this.model.findBone("rotate")
    },
    turnDir(pos){
        let degree = this._super(pos)
        this.bone.rotation = -degree
    },
    IdelAction(param){
        this._super(param)
        this.bone.rotation = 0
    },
    attack(param){
        this._super(param)
        let bullet_param = this.info.bulletParam.split("#")
        let scale_sec = parseInt(bullet_param[0]) / (this.info.bulletSpeed * BULLET_SPEED) // 缩小所需时间
        let scale_sub = (1 - parseFloat(bullet_param[1])) / scale_sec   // 每秒需要缩小多少

        let bullet = {
            pos : this.getBulletWorldPos(),          // 初始位置
            damege: this.damege,                    // 伤害
            dir: this.v2Target(),                   // 方向
            script:this.info.bullet,                // 子弹脚本
            voice: this.info.bulletVoice,           // 子弹声音
            through: this.info.through,
            speed: this.info.bulletSpeed,           // 子弹速度
            collider: this.info.bulletCollider,     // 碰撞形状
            attack_fly: true,                       // 是否可攻击空中单位
            max_distance:parseInt(bullet_param[0]), // 最远距离
            scale_sub : scale_sub,                  //                    
            style:{                             // 子弹样式
                skin: this.role_info.bulletSkin,
                url:'spine/bullet/' + this.info.bulletModel,
                type:sp.SkeletonData
            },
            effect:[],                          // 子弹效果
        }
        bullet = this.getRoleBulletSkill(bullet)  // 通过羊群获得子弹效果        
        if(!bullet.dir.equals(cc.Vec2.ZERO)){
            gg.bulletManager.addBullet(bullet)
        }
    }
});
